<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>拣选台绑盘</title>
    <script th:src="@{/js/jquery.min.js}"></script>
</head>
<body>
<table id="tbb" width="98%" border="1" align="center" cellPadding="0" cellSpacing="0">

    <tr>
        <td align="center">货位码:</td>
        <td><input id="cargoSpaceId" type="text" name="cargoSpaceId" style="width: 50%"/>
    </tr>

    <tr>
        <td align="center">托盘码:</td>
        <td><input id="trayCode" type="text" name="trayCode" style="width: 50%"/>
    </tr>

    <tr>
        <td align="center">物料码:</td>
        <td><input id="productId" type="text" name="productId" style="width: 50%"/>
    </tr>

    <tr>
        <td align="center">入库数量:</td>
        <td><input id="quantity" type="text" name="quantity" style="width: 50%"/>
    </tr>

    <tr>
        <td height="25" bgcolor="#d9e8fc" align="center" colSpan="2">
            <table width="100%">
                <tr>
                    <td width="40%" align="center">
                        <button id="btn_submit" type="button" onclick="pickingIn()" style="width:30%">提交</button>
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    <script>

        // 获取输入框元素
        var cargoSpaceId = document.getElementById('cargoSpaceId');
        var trayCode = document.getElementById('trayCode');
        var productId = document.getElementById('productId');
        var quantity = document.getElementById('quantity');

        function pickingIn() {
            //控制按钮多次点击
            var btn = document.getElementById('btn_submit');//首先需要获取的是哪一个按钮的id
            btn.disabled = 'disabled';//只要点击就将按钮的可点击的状态更改为不可以点击的状态
            setTimeout(function () {//设置时间，多久可以改变状态为可以点击
                btn.disabled = '';
            }, 3000);

            //验证数据完成性
            var cargoSpaceId = document.getElementById("cargoSpaceId").value;
            if (cargoSpaceId == "") {
                alert("货位码不能为空");
                document.getElementById("cargoSpaceId").focus();
                return;
            }
            var trayCode = document.getElementById("trayCode").value;
            if (trayCode == "") {
                alert("托盘码不能为空");
                document.getElementById("trayCode").focus();
                return;
            }
            var productId = document.getElementById("productId").value;
            if (productId == "") {
                alert("物料编号不能为空");
                document.getElementById("productId").focus();
                return;
            }
            var quantity = document.getElementById("quantity").value;
            if (quantity == "") {
                alert("入库数量不能为空");
                document.getElementById("quantity").focus();
                return;
            }
            $.ajax({
                url: "/pda/pickingIn",
                method: "POST",
                data: JSON.stringify({
                    cargoSpaceId: cargoSpaceId,
                    productId: productId,
                    trayCode: trayCode,
                    quantity: quantity
                }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    // 处理响应结果
                    console.log(result);
                    alert(result.msg)
                    window.location.reload();
                },
                error: function (xhr, status, error) {
                    // 处理错误信息
                    console.log(error);
                }
            });
        }
    </script>
</table>
</body>
</html>